Skip to content

Commit 33ed97e

Browse files
authored
Merge pull request #6599 from emilghittasv/playwright-fix-test-failures
Playwright fix test failures and improve the pytest_runtest_makereport hook
2 parents 5eb60f2 + 977f4aa commit 33ed97e

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

playwright_tests/tests/ask_a_question_tests/aaq_tests/test_aaq_form_page.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,11 @@ def test_loginless_mozilla_account_aaq(page: Page):
521521
"blocked after 3 submissions"):
522522
i = 1
523523
while i <= 4:
524-
sumo_pages.top_navbar.click_on_signin_signup_button()
524+
# In case a 502 error occurs we might end up in the auth page after the automatic
525+
# refresh/retry so we need to skip the signin_signup button click since the
526+
# element is not available.
527+
if sumo_pages.top_navbar.is_sign_in_up_button_displayed():
528+
sumo_pages.top_navbar.click_on_signin_signup_button()
525529
sumo_pages.auth_page.click_on_cant_sign_in_to_my_mozilla_account_link()
526530
sumo_pages.aaq_flow.submit_an_aaq_question(
527531
subject=utilities.aaq_question_test_data['premium_aaq_question']['subject'],

playwright_tests/tests/ask_a_question_tests/aaq_tests/test_posted_questions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1332,8 +1332,9 @@ def test_solves_this_problem(page: Page):
13321332
sumo_pages.aaq_flow.deleting_question_flow()
13331333

13341334

1335-
# Need to add test for preview as well.
13361335
# T5696791, T5696772, T5696774, T5696776, T5696792
1336+
# Skipped until we decide if we should revert https://github.com/mozilla/sumo/issues/2245 or not
1337+
@pytest.mark.skip
13371338
@pytest.mark.postedQuestions
13381339
@pytest.mark.parametrize("quote_on", ['reply', 'question'])
13391340
def test_quote_reply_functionality(page: Page, quote_on):

playwright_tests/tests/conftest.py

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -41,36 +41,29 @@ def handle_502_error(response):
4141
return page
4242

4343

44+
@pytest.hookimpl(hookwrapper=True)
4445
def pytest_runtest_makereport(item, call) -> None:
4546
"""
4647
This pytest hook is triggered after each test execution.
47-
If a test failure occurred we are saving & attaching the test execution screencast to the
48-
allure report for better debugging.
48+
If a test failure occurred (including pytest assertion failures) we are saving & attaching the
49+
test execution screencast to the allure report for better debugging.
4950
"""
50-
if call.when == "call":
51-
# Check if the test has raised an exception (test failed or encountered an error during
52-
# execution). Also checks if the test function has the page instance in its arguments
53-
# ensuring that video recording is applied only when the test involves playwright
54-
# automation.
55-
if call.excinfo is not None and "page" in item.funcargs:
56-
# Retrieve the page object from the test function arguments.
57-
page: Page = item.funcargs["page"]
58-
# Provide the path to the recorded video (the video recording starts when the browser
59-
# context is created).
60-
video_path = page.video.path()
61-
# Ensure that the browser context is closed after test. Closing the context also
62-
# ensures that the video is properly saved.
63-
page.context.close()
64-
# Attaching the video to the Allure report:
65-
# 1. Opening the video file in binary mode and reading its content.
66-
# 2. Assigning a name to the video attachment based on the slugyfied version of the
67-
# test node id.
68-
# 3. Saving the video as a .webm extension.
69-
allure.attach(
70-
open(video_path, 'rb').read(),
71-
name=f"{slugify(item.nodeid)}.webm",
72-
attachment_type=allure.attachment_type.WEBM
73-
)
51+
52+
outcome = yield # Capture the result of the test execution.
53+
report = outcome.get_result() # Retrieve the test execution report.
54+
55+
# Ensure the test has failed and involves Playwright automation.
56+
if report.failed and "page" in item.funcargs:
57+
page: Page = item.funcargs["page"] # Retrieve the page object from the test function args.
58+
video_path = page.video.path() # Retrieve the path to the recorded video.
59+
page.context.close() # Close the browser context to ensure the video is properly saved.
60+
61+
# Attaching the video to the Allure report:
62+
allure.attach(
63+
open(video_path, 'rb').read(),
64+
name=f"{slugify(item.nodeid)}.webm",
65+
attachment_type=allure.attachment_type.WEBM
66+
)
7467

7568

7669
@pytest.fixture()

playwright_tests/tests/explore_help_articles_tests/explore_by_topic_tests/test_explore_by_topics.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ def test_explore_by_topic_product_filter(page: Page):
3535
if product.strip() == "All Products":
3636
continue
3737
else:
38-
sumo_pages.explore_by_topic_page.select_a_filter_by_product_option(
39-
product.strip())
40-
time.sleep(2)
38+
with page.expect_navigation(timeout=3000) as navigation_info:
39+
sumo_pages.explore_by_topic_page.select_a_filter_by_product_option(
40+
product.strip())
41+
response = navigation_info.value
42+
if response is None:
43+
print("Navigation did not occur. Refreshing the page.")
44+
utilities.refresh_page()
4145
if not sumo_pages.explore_by_topic_page.get_metadata_of_all_listed_articles():
4246
pytest.fail(f"There is no sublist for {product}")
4347

playwright_tests/tests/messaging_system_tests/test_messaging_system.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ def test_group_messages_cannot_be_sent_by_non_staff_users(page: Page):
782782
)
783783

784784
with allure.step("Verifying that no users are returned"):
785-
expect(sumo_pages.new_message_page.get_no_user_to_locator()).to_be_visible(timeout=10000)
785+
expect(sumo_pages.new_message_page.get_no_user_to_locator()).to_be_visible(timeout=15000)
786786

787787
with allure.step("Navigating to the groups page"):
788788
utilities.navigate_to_link(utilities.general_test_data['groups'])
@@ -1053,7 +1053,7 @@ def test_unable_to_send_group_messages_to_profiless_groups(page: Page):
10531053
sumo_pages.new_message_page.type_into_new_message_to_input_field("kb-contributors")
10541054

10551055
with allure.step("Verifying that no users are returned"):
1056-
expect(sumo_pages.new_message_page.get_no_user_to_locator()).to_be_visible(timeout=10000)
1056+
expect(sumo_pages.new_message_page.get_no_user_to_locator()).to_be_visible(timeout=15000)
10571057

10581058

10591059
# C2083482

0 commit comments

Comments
 (0)